﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace HowItWentDown
{
    class Disappear : Obj
    {
        public float maxFrames = 60, maxAlpha = 1, alphaFadeOutSpeed = 0.05f, alphaFadeInSpeed = 0.2f;
        float frames = 0;
        /// <summary>
        /// A class for objects that appear and dissappear after a certain time, such as particles. To customize it, set maxFrames, maxAlpha, alphaFadeOutSpeed and alphaFadeInSpeed
        /// </summary>
        /// <param name="Doc"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        /// <param name="Z"></param>
        /// <param name="Tex"></param>
        public Disappear(Game1 Doc, float X, float Y, float Z, Texture2D Tex)
            :base(Doc,X,Y,Z,Tex, false)
        {
            alpha = 0;
        }
        public override void Update()
        {
            // add onto the frame count in each update
            frames += Global.Speed;
            // if the number of frames is below the maximum number of allowed frames, fade the object in
            if (frames < maxFrames)
            {
                if (alpha < maxAlpha)
                {
                    alpha += alphaFadeInSpeed * Global.Speed;
                }
                else alpha = maxAlpha;
            }
                // if the number of frames is above the maximum number of allowed frames, fade the object out
            else
            {
                if (alpha > 0)
                {
                    alpha -= alphaFadeOutSpeed * Global.Speed;
                }
                    // when the object is fully faded out, destroy it
                else
                {
                    remove();
                }
            }
            base.Update();
        }
    }
}
